package com.team.ai.service;

import com.team.ai.entity.Paper;
import com.team.ai.entity.Question;
import com.team.ai.entity.ResultEntity;
import com.team.ai.mapper.PaperMapper;
import com.team.ai.mapper.QuestionMapper;
import com.team.ai.mapper.VideoMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

@Transactional
@Service
public class PaperService {
    @Resource
    PaperMapper paperMapper;
    @Resource
    QuestionMapper questionMapper;
    public String selectPaper(String paper){
        try{
            List<Paper> papers = paperMapper.selectPaper(paper);
            List<Question> questions = new LinkedList<>();
            for (int i = 0; i < papers.size(); i++) {
                questions.add(questionMapper.getQuestionById(papers.get(i).getQuestionid()));
            }
            return ResultEntity.success(questions) ;
        }catch (Exception e){
            e.printStackTrace();
            return  ResultEntity.fail(-10005);
        }
    }
}
